import { FormSchema } from '/@/components/Form';
import { BasicColumn } from '/@/components/Table';
import { render } from '/@/utils/common/renderUtils';
function formatDate(timestamp: number | null | undefined): string {
  if (!timestamp) {
    return ''; // Return an empty string if the timestamp is null or undefined
  }
  const date = new Date(timestamp);
  const year = date.getFullYear();
  const month = String(date.getMonth() + 1).padStart(2, '0');
  const day = String(date.getDate()).padStart(2, '0');
  return `${year}-${month}-${day}`;
}
export const columns: BasicColumn[] = [
  {
    title: '用户账号',
    dataIndex: 'username',
    width: 120,
  },
  {
    title: '姓名',
    dataIndex: 'realname',
    width: 150,
  },
  {
    title: '性别',
    dataIndex: 'sex',
    width: 80,
    sorter: true,
    customRender: ({ text }) => {
      return render.renderDict(text, 'sex');
    },
  },
  {
    title: '出生年月',
    dataIndex: 'birthday',
    width: 100,
    customRender: ({ text }) => {
      return formatDate(text);
    },
  },
  {
    title: '职务',
    dataIndex: 'post',
    width: 150,
    slots: { customRender: 'post' },
  },
  {
    title: '任职时间',
    dataIndex: 'tenure',
    width: 100,
    customRender: ({ text }) => {
      return formatDate(text);
    },
  },
  {
    title: '聘任时间',
    dataIndex: 'hiringTime',
    width: 100,
    customRender: ({ text }) => {
      return formatDate(text);
    },
  },
  {
    title: '是否党员',
    dataIndex: 'cpc',
    width: 100,
    customRender: ({ text }) => {
      return text === 1 ? '是' : text === 2 ? '否' : '';
    },
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    label: '姓名',
    field: 'realname',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    label: '工号',
    field: 'workNo',
    component: 'Input',
    colProps: { span: 6 },
  },
];
